﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.SceneManagement;

public class EditSceneScript : MonoBehaviour {

	public Text showText;
	public InputField cameraIF;
	public InputField BGIF;
	public InputField FWIF;
	public InputField cameraMaxIF;
	public InputField flyTimeIF;
	public Toggle select;
	// Use this for initialization
	void Start () {
		
	}
	
	// Update is called once per frame
	void Update () {
		
	}

	public void ButtonClick(){
		var cStr = cameraIF.text;
		var bStr = BGIF.text;
		var fStr = FWIF.text;
		var cmStr = cameraMaxIF.text;
		var ftStr = flyTimeIF.text;
		bool sel = select.isOn;
		if (sel == true) {
			PlayerPrefs.SetInt ("select", 1);
		} else {
			PlayerPrefs.SetInt ("select", 0);
			PlayerPrefs.Save ();
			return;
		}
		float cSpeed = float.Parse (cStr);
		float bSpeed = float.Parse (bStr);
		float fSpeed = float.Parse (fStr);
		float cmSpeed = float.Parse (cmStr);
		float ftSpeed = float.Parse (ftStr);
		if (cStr != "" && cStr != null && cSpeed > 0.000010f) {
			PlayerPrefs.SetInt ("hasCamera", 1);
			PlayerPrefs.SetFloat ("cameraIF", cSpeed);
		} else {
			PlayerPrefs.SetInt ("hasCamera", 0);
		}
		if (bStr != "" && bStr != null && bSpeed > 0.000010f) {
			PlayerPrefs.SetInt ("hasBg", 1);
			PlayerPrefs.SetFloat ("bgIF", bSpeed);
		} else {
			PlayerPrefs.SetInt ("hasBg", 0);
		}
		if (fStr != "" && fStr != null && ftSpeed > 0.000010f) {
			PlayerPrefs.SetInt ("hasForward", 1);
			PlayerPrefs.SetFloat ("forwardIF", fSpeed);
		} else {
			PlayerPrefs.SetInt ("hasForward", 0);
		}
		if (cmStr != "" && cmStr != null && cmSpeed > 0.000010f) {
			PlayerPrefs.SetInt ("hasCameraMaxSpeed", 1);
			PlayerPrefs.SetFloat ("cameraMaxSpeed", cmSpeed);
		} else {
			PlayerPrefs.SetInt ("hasCameraMaxSpeed", 0);
		}
		if (ftStr != "" && ftStr != null && ftSpeed > 0.000010f) {
			PlayerPrefs.SetInt ("hasFlyTime", 1);
			PlayerPrefs.SetFloat ("flyTime", ftSpeed);
		} else {
			PlayerPrefs.SetInt ("hasFlyTime", 0);
		}
		PlayerPrefs.Save ();
	}

	public void Back(){
		SceneManager.LoadScene ("Index");
	}
}
